import request from "@/utils/request";
import type {
  GetRoleListParams,
  GetRoleListResponse,
  GetRolePermissionListApiResponse,
} from "./type/roleType";
const enum Api {
  getRoleList = "/admin/acl/role",
  addRole = "/admin/acl/role/save",
  getRolePermissionList = "/admin/acl/permission/toAssign",
  assignRolePermissionList = "/admin/acl/permission/doAssign",
}
export const getRoleListApi = ({
  page,
  limit,
  roleName,
}: GetRoleListParams) => {
  return request.get<any, GetRoleListResponse>(
    Api.getRoleList + `/${page}/${limit}`,
    {
      params: {
        roleName,
      },
    }
  );
};
// 添加角色
export const addRoleApi = (data: { roleName: string }) => {
  return request.post<any, null>(Api.addRole, data);
};
// 获取角色的菜单列表
export const getRolePermissionListApi = (roleId: string) => {
  return request.get<any, GetRolePermissionListApiResponse>(
    Api.getRolePermissionList + `/${roleId}`
  );
};
// 给角色分配菜单列表
export const assignRolePermissionListApi = (
  roleId: string,
  permissionId: string[]
) => {
  return request.post<any, null>(
    Api.assignRolePermissionList,
    {},
    {
      params: {
        roleId,
        permissionId: permissionId.join(","),
      },
    }
  );
};
